package com.test.deencredit.fragment_deencredit.main_deencredit;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.test.deencredit.R;
import com.test.deencredit.activity_deencredit.FeedbackActivity_deencredit;
import com.test.deencredit.activity_deencredit.SettingActivity_deencredit;
import com.test.deencredit.base_deencredit.BaseFragment_deencredit;
import com.test.deencredit.bean_deencredit.config_deencredit.AppShowCustomize_deencredit;
import com.test.deencredit.dialog_deencredit.CustomerServiceDialog_deencredit;
import com.test.deencredit.dialog_deencredit.RateNormalDialog_deencredit;
import com.test.deencredit.util_deencredit.UserInfoUtil_deencredit;
import com.test.deencredit.util_deencredit.http_deencredit.HttpUtil_deencredit;

public class PersonalCenterFragment_deencredit extends BaseFragment_deencredit {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        page_deencredit = "ME";
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_personal_center_deencredit, container, false);
        init_deencredit(view);
        return view;
    }

    private void init_deencredit(View view){

        TextView mobileTv = view.findViewById(R.id.fpc_tv_mobile);

        view.findViewById(R.id.fpc_ib_customerservice).setOnClickListener(v -> new CustomerServiceDialog_deencredit(requireContext()).show());

        mobileTv.setText(UserInfoUtil_deencredit.getInstance_deencredit().getEncryptMobile_deencredit());

        //feedback
        view.findViewById(R.id.fpc_view_feedback).setOnClickListener(v -> {
            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"FEEDBACK_CLICK","");
            startActivity(new Intent(requireContext(), FeedbackActivity_deencredit.class));
        });

        //privacypolicy
        view.findViewById(R.id.fpc_view_privacypolicy).setOnClickListener(v -> {
            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"PRIVACY_POLICY_CLICK","");
            String agreementUrl = AppShowCustomize_deencredit.getInstance_deencredit().getAgreementUrl_deencredit();
            if (TextUtils.isEmpty(agreementUrl)) return;
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(agreementUrl)));
        });

        //Rate us
        view.findViewById(R.id.fpc_view_rate_us).setOnClickListener(v -> new RateNormalDialog_deencredit(requireActivity()).show());

        //setting
        view.findViewById(R.id.fpc_view_setting).setOnClickListener(v -> {
            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit,"SETTING_CLICK","");
            startActivity(new Intent(requireContext(), SettingActivity_deencredit.class));
        });

    }

}